<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <link href="css/mui.min.css" rel="stylesheet"/>
	<link rel="stylesheet" href="css/style.css" />
</head>
<body>
.
	<header class="mui-bar mui-bar-nav password_retrieval_header">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">找回密码</h1>
	</header>
	<div class="mui-content">
		<form class="password_retrieval">
			<input id="Phone" type="text" placeholder="请输入手机号"/>
			<div class="verification">
				<input id="Code" type="text" placeholder="请输入短信验证码"/><span id="getCode">获取验证码</span>
			</div>
			<input id="Password" type="text" placeholder="请输密码，6-13位英文或数字"/>
			<button type="button" class="password_retrieval_btn" id="saveBtn" onclick="">提交</button>
		</form>
	</div>
	<script src="js/mui.min.js"></script>
	<script src="js/config.js"></script>
	<script src="js/comn.js"></script>
	<script src="js/login.js"></script>
 	<script type="text/javascript" charset="utf-8">
 	mui.plusReady(function(){
 		var getting = false;
 		mui.init();
 		state = app.getState();
 		var PhoneBox = document.getElementById('Phone');
 		var Code = document.getElementById('Code');
 		var PasswordBox = document.getElementById('Password');
 		mui('#saveBtn')[0].addEventListener('tap',function(event){
 			//验证手机号
 			var reg_phone = /^1[34578]\d{9}$/;
 			if(!reg_phone.test(PhoneBox.value)){
 				mui.toast('手机号格式错误');return;
 			}
 			//验证code
 			var reg_code = /^\d{6}$/;
 			if(!reg_code.test(Code.value)){
 				mui.toast('验证码错误');return;
 			}
 			//验证密码
 			var reg_password = /^[a-zA-Z][a-zA-Z0-9_]{6,18}$/;
 			if(!reg_password.test(PasswordBox.value)){
 				mui.toast('密码格式错误,请输入6-18位字母，数字或下划线');return;
 			}
 			plus.nativeUI.showWaiting();
 			app.resetPassword(Code.value,PasswordBox.value,function(info){
 				if(info){
 					mui.toast(info);
 				}else{
 					mui.toast('密码已重置');
 				}
 			});
 			
 			
 		});
 		
 		mui('#getCode')[0].addEventListener('tap',function(event){
			var reg_phone = /^1[34578]\d{9}$/;
			if(reg_phone.test(PhoneBox.value)){
				if(!getting){
					plus.nativeUI.showWaiting();
					app.getCode(PhoneBox.value,function(info){
						if(info){
							mui.toast(info);
						}else{
							mui.toast('短信验证码已发送');
							codeInterval();
						}
					});
				}
			}else{
				console.log(PhoneBox.value);
				mui.toast('手机号格式错误');
			}
		});
		function codeInterval(){
			var i = 5;
			var getCodeBox = document.getElementById('getCode');
			var CodeText = getCodeBox.innerText;
			var index = setInterval(function(){
				if(i<1){
					getCode.innerText = CodeText;
					clearInterval(index);
					getting = false;
					return;
				}
				getCode.innerText = '('+i+')' + CodeText;
				i--;
			},1000);
			getting = true;
		}
		
 	});
      	
    </script>
</body>
</html>